package pw.goyd.game.logic;

import pw.goyd.game.model.Room;
import pw.goyd.game.model.Seat;
import pw.goyd.protocol.core.Serializer;
import pw.goyd.subscribe.PlayerCustomer;

import java.util.List;

/**
 * 返回匹配房间
 *
 * @author StanWind
 */
public class GetPlayResponse extends Serializer {
    private Room room;

    public Room getRoom() {
        return room;
    }

    public void setRoom(Room room) {
        this.room = room;
    }

    @Override
    protected void read() {

    }

    @Override
    protected void write() {
        //房间号
        writeInt(room.getRoomID());
        //是否正在游戏
        if (room.isGame())
            writeByte((byte) 1);
        else
            writeByte((byte) 0);

        List<Seat> ss = room.getSeats();
        int i = 0;
        for (Seat s : ss) {
            i++;
            PlayerCustomer player = s.getPlayer();
            if (player != null) {
                writeByte((byte) i);                    //  座位号
                writeString(player.getAccount_id());    //  玩家唯一ID
                writeString(player.getIcon_source());   //  头像
                writeString(player.getNickname());      //  NickName
                writeInt(player.getGold());             //  Gold
                if (player.isReady()) {
                    writeByte((byte) 1);                //  准备
                } else {
                    writeByte((byte) 0);                //  未准备
                }
            }

        }


    }

}
